<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:form>
                    <p:panel>
                    <f:facet name="header">
                        <h:outputLabel value="INWARD CREDIT ACCESS"/>
                    </f:facet>
                    <h:panelGrid columns="2" >
                        <h:outputLabel value="From Date"/>
                        <p:calendar id="fromDate" value="#{creditCompanyDueController.fromDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >
                            <f:ajax event="dateSelect" execute="toDate @this"  render="lst"/>
                        </p:calendar>
                        <h:outputLabel value="To Date"/>
                        <p:calendar id="toDate" value="#{creditCompanyDueController.toDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >
                            <f:ajax event="dateSelect" execute="@this fromDate"  render="lst"/>
                        </p:calendar>
                        <p:spacer width="100" height="1"/>
                        
                    </h:panelGrid>
                        
                        <p:commandButton ajax="false" value="Process Cash ACCESS" action="#{creditCompanyDueController.createInwardCashAccess()}" onclick="onSubmitButton();"/>
                        
                        <p:commandButton ajax="false" value="Print" styleClass="noPrintButton" >
                            <p:printer target="lst"  />
                        </p:commandButton>

                        <p:commandButton actionListener="#{creditCompanyDueController.createInwardCreditDue()}" ajax="false" value="Excel" styleClass="noPrintButton" >
                            <pe:exporter type="xlsx" target="lst" fileName="Due Search(Credit Company)" subTable="true" />
                        </p:commandButton>

                    <p:dataTable id="lst" value="#{creditCompanyDueController.institutionEncounters}" var="i">
                        <f:facet name="header">
                                <h:outputLabel value="EXCESS SEARCH"/>
                                <h:outputLabel value="&emsp;&emsp;From :  " style="white-space: pre-line"/>
                                <h:outputLabel value="#{creditCompanyDueController.fromDate}">
                                    <f:convertDateTime pattern="dd MMMM yyyy hh:mm:ss a"/>
                                </h:outputLabel>
                                <h:outputLabel value="&emsp;&emsp;To  :  "/>
                                <h:outputLabel value="#{creditCompanyDueController.toDate}">
                                    <f:convertDateTime pattern="dd MMMM yyyy hh:mm:ss a"/>
                                </h:outputLabel>
                            </f:facet>
                        <p:columnGroup type="header">
                            <p:row>
                                <p:column headerText="Patient Encounter">                                    
                                </p:column>
                                <p:column headerText="Patient Name">                                    
                                </p:column>
                                <p:column headerText="Used Amount">                                    
                                </p:column>
                                <p:column headerText="Paid Amount">                                    
                                </p:column>
                                 <p:column headerText="Net Amount">                                    
                                </p:column>
                            </p:row>
                        </p:columnGroup>
                        <p:subTable value="#{i.patientEncounters}" var="b">
                            <f:facet name="header">
                                <h:outputLabel  value="#{i.institution.name}"/>
                            </f:facet>
                            <p:column>                              
                                <h:outputLabel value="#{b.bhtNo}" />                                
                            </p:column>
                            <p:column>                               
                                <h:outputLabel value="#{b.patient.person.nameWithTitle}" />                                 
                            </p:column>
                            <p:column style="text-align: right;">                                
                                <h:outputLabel value="#{b.creditUsedAmount}" >
                                    <f:convertNumber pattern="#,##0.00" />
                                </h:outputLabel>                                 
                            </p:column>
                            <p:column style="text-align: right;">                              
                                <h:outputLabel value="#{b.creditPaidAmount}" >
                                    <f:convertNumber pattern="#,##0.00" />
                                </h:outputLabel>
                            </p:column>
                            <p:column style="text-align: right;">                              
                                <h:outputLabel value="#{b.creditUsedAmount+b.creditPaidAmount}" >
                                    <f:convertNumber pattern="#,##0.00" />
                                </h:outputLabel>
                            </p:column>
                            <p:columnGroup type="footer">
                                <p:row>
                                    <p:column footerText="Total" colspan="2" />
                                    <p:column style="text-align: right;">
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{i.total}">
                                                <f:convertNumber pattern="#,##0.00" />
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>
                                    <p:column style="text-align: right;" >
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{i.paidTotal}">
                                                <f:convertNumber pattern="#,##0.00" />
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>
                                     <p:column style="text-align: right;" >
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{i.total+i.paidTotal}">
                                                <f:convertNumber pattern="#,##0.00" />
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>
                                </p:row>
                            </p:columnGroup>
                        </p:subTable>
                            <f:facet name="footer" >
                                <h:outputLabel value="Printed By : #{sessionController.loggedUser.webUserPerson.name}" style="float: right"/>
                            </f:facet>

                    </p:dataTable>
                        </p:panel>
                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
